﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Toolkit.Web.ExtensionMethods;
using Toolkit.Web.Infastructure;

namespace Toolkit.Web.ViewComponents.DataGrid
{
    public sealed class DataGridColumnFilterFactory<T> where T : class
    {
        private readonly DataGridColumn<T> _container;

        public DataGridColumnFilterFactory(DataGridColumn<T> container)
        {
            if (container == null)
            {
                throw new ArgumentNullException("container");
            }

            _container = container;
        }

        public DataGridColumnFilterBuilder AddFilter(string key, DataGridColumnFilterType filterType, string expression, Type valueType)
        {
            DataGridColumnFilter filter = new DataGridColumnFilter(key, filterType, expression, valueType);

            if (_container.Filters == null)
            {
                _container.Filters = new List<DataGridColumnFilter>();
            }

            _container.Filters.Add(filter);

            return new DataGridColumnFilterBuilder(filter);
        }
    }
}
